~ function () {
  var sidebar = $("#sidebar"),
    mask = $(".mask"),
    sidebar_trigger = $("#sidebar_trigger"),
    backButton = $(".back-to-top")

  var showSideBar = function () {
    mask.fadeIn();
    sidebar.css('right', 0)
  }

  var hideSideBar = function () {
    mask.fadeOut();
    sidebar.css('right', -sidebar.width())
  }

  sidebar_trigger.on('click', showSideBar)
  mask.on('click', hideSideBar)
  backButton.on('click', function () {
    $("html,body").animate({
      scrollTop: 0
    }, 800)
  })

  $(window).on('scroll', function () {
    if ($(this).scrollTop() > $(this).height()) {
      backButton.fadeIn();
    } else {
      backButton.fadeOut()
    }
  })
  $(window).trigger("scroll")
}()